package com.framework.view.indicator.configs;

import androidx.annotation.ColorInt;
import androidx.annotation.Dimension;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * 标题的抽象配置类，抽取公共配置
 *
 * @author liangzx
 * @version 1.0
 * @time 2019-12-14 16:21
 **/
public abstract class AbstractTitleConfig<T extends AbstractTitleConfig> {

    /**
     * 未选中大小
     */
    private int normalSize;
    /**
     * 选中大小
     */
    private int selectedSize;
    /**
     * 未选中颜色
     */
    private int normalColor;
    /**
     * 选中颜色
     */
    private int selectedColor;
    /**
     * 是否未选中字体加粗
     */
    private boolean isNormalBold;
    /**
     * 是否选中字体加粗
     */
    private boolean isSelectedBold;
    /**
     * 未选中颜色列表
     */
    private List<Integer> normalColors;
    /**
     * 选中颜色列表
     */
    private List<Integer> selectedColors;
    /**
     * 颜色是否跟随滑动渐变
     */
    boolean isColorGradientFollowSlide;
    /**
     * 大小是否随滑动逐渐变化
     */
    private boolean isSizeFollowSlideChange;
    /**
     * 是否使用颜色裁剪效果
     */
    boolean isUseColorClip;
    /**
     * 左间距
     */
    private int pendingLeft;
    /**
     * 右间距
     */
    private int pendingRight;
    /**
     * 中间分隔线配置
     */
    private MidDividerConfig midDividerConfig;

    /**
     * 未选中大小
     *
     * @param normalSize
     * @return
     */
    public T setNormalSize(@Dimension int normalSize) {
        this.normalSize = normalSize;
        return (T) this;
    }

    /**
     * 选中大小
     *
     * @param selectedSize
     * @return
     */
    public T setSelectedSize(@Dimension int selectedSize) {
        this.selectedSize = selectedSize;
        return (T) this;
    }

    /**
     * 未选中颜色
     *
     * @param normalColor
     * @return
     */
    public T setNormalColor(@ColorInt int normalColor) {
        this.normalColor = normalColor;
        return (T) this;
    }

    /**
     * 选中颜色
     *
     * @param selectedColor
     * @return
     */
    public T setSelectedColor(@ColorInt int selectedColor) {
        this.selectedColor = selectedColor;
        return (T) this;
    }

    /**
     * 未选中颜色列表
     *
     * @param normalColors
     * @return
     */
    public T setNormalColors(@ColorInt List<Integer> normalColors) {
        this.normalColors = normalColors;
        return (T) this;
    }

    /**
     * 设置选中时文本控件字体的颜色列表，对应needAutoChangeTxtIds的id列表
     *
     * @param normalColors
     * @return
     */
    public T setNormalColors(@ColorInt Integer... normalColors) {
        return setNormalColors(Arrays.asList(normalColors));
    }

    /**
     * 添加未选中颜色到列表，支持多次添加
     *
     * @param normalColor
     * @return
     */
    public T addNormalColors(@ColorInt int normalColor) {
        if (null == normalColors) {
            normalColors = new ArrayList<>(5);
        }
        normalColors.add(normalColor);
        return (T) this;
    }

    /**
     * 选中颜色列表
     *
     * @param selectedColors
     * @return
     */
    public T setSelectedColors(@ColorInt List<Integer> selectedColors) {
        this.selectedColors = selectedColors;
        return (T) this;
    }

    /**
     * 选中颜色列表
     *
     * @param selectedColors
     * @return
     */
    public T setSelectedColors(@ColorInt Integer... selectedColors) {
        setSelectedColors(Arrays.asList(selectedColors));
        return (T) this;
    }

    /**
     * 添加选中颜色到列表，支持多次添加
     *
     * @param selectedColor
     * @return
     */
    public T addSelectedColor(@ColorInt int selectedColor) {
        if (null == selectedColors) {
            selectedColors = new ArrayList<>(5);
        }
        selectedColors.add(selectedColor);
        return (T) this;
    }

    /**
     * 设置未选中字体是否加粗
     *
     * @param isNormalBold
     * @return
     */
    public T setNormalBold(boolean isNormalBold) {
        this.isNormalBold = isNormalBold;
        return (T) this;
    }

    /**
     * 设置选中字体是否加粗
     *
     * @param isSelectedBold
     * @return
     */
    public T setSelectedBold(boolean isSelectedBold) {
        this.isSelectedBold = isSelectedBold;
        return (T) this;
    }

    /**
     * 颜色是否随滑动渐变
     *
     * @param isColorGradientFollowSlide
     * @return
     */
    public T setColorGradientFollowSlide(boolean isColorGradientFollowSlide) {
        if (isUseColorClip) {
            throw new IllegalArgumentException("if u set setUseColorClip(true),then u cann't setColorGradientFollowSlide(true)");
        }
        this.isColorGradientFollowSlide = isColorGradientFollowSlide;
        return (T) this;
    }

    /**
     * 大小是否随滑动逐渐变化
     *
     * @param sizeFollowSlideChange
     * @return
     */
    public T setSizeFollowSlideChange(boolean sizeFollowSlideChange) {
        isSizeFollowSlideChange = sizeFollowSlideChange;
        return (T) this;
    }

    /**
     * 左间距
     *
     * @param pendingLeft
     * @return
     */
    public T setPendingLeft(@Dimension int pendingLeft) {
        this.pendingLeft = pendingLeft;
        return (T) this;
    }

    /**
     * 右间距
     *
     * @param pendingRight
     * @return
     */
    public T setPendingRight(@Dimension int pendingRight) {
        this.pendingRight = pendingRight;
        return (T) this;
    }

    /**
     * 设置中间分隔线的配置
     *
     * @param midDividerConfig
     * @return
     */
    public T setMidDividerConfig(MidDividerConfig midDividerConfig) {
        this.midDividerConfig = midDividerConfig;
        return (T) this;
    }

    public int getNormalSize() {
        return normalSize;
    }

    public int getSelectedSize() {
        return selectedSize;
    }

    public int getNormalColor() {
        return normalColor;
    }

    public int getSelectedColor() {
        return selectedColor;
    }

    public List<Integer> getNormalColors() {
        return normalColors;
    }

    public List<Integer> getSelectedColors() {
        return selectedColors;
    }

    public boolean isNormalBold() {
        return isNormalBold;
    }

    public boolean isSelectedBold() {
        return isSelectedBold;
    }

    /**
     * 根据当前标题所属位置获取未选中的颜色值<br>
     * 该方法先判断颜色列表是否为空，如空则取单个颜色，非空则取颜色列表中对应位置的值，超出下标则取最后一个
     *
     * @param index
     * @return
     */
    public int getNormalColorByPosition(int index) {
        if (null == normalColors || normalColors.isEmpty()) {
            return normalColor;
        }
        if (normalColors.size() <= index) {
            return normalColors.get(normalColors.size() - 1);
        }
        return normalColors.get(index);
    }

    /**
     * 根据当前标题所属位置获取选中的颜色值<br>
     * 该方法先判断颜色列表是否为空，如空则取单个颜色，非空则取颜色列表中对应位置的值，超出下标则取最后一个
     *
     * @param index
     * @return
     */
    public int getSelectedColorByPosition(int index) {
        if (null == selectedColors || selectedColors.isEmpty()) {
            return selectedColor;
        }
        if (selectedColors.size() <= index) {
            return selectedColors.get(selectedColors.size() - 1);
        }
        return selectedColors.get(index);
    }

    public boolean isColorGradientFollowSlide() {
        return isColorGradientFollowSlide;
    }

    public boolean isSizeFollowSlideChange() {
        return isSizeFollowSlideChange;
    }

    public int getPendingLeft() {
        return pendingLeft;
    }

    public int getPendingRight() {
        return pendingRight;
    }

    public MidDividerConfig getMidDividerConfig() {
        return midDividerConfig;
    }
}
